using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using LZX.MEditor.Enum;
using LZX.MEditor.LZXStatic;
using LZX.MEditor.MScriptableObject;
using LZX.MEditor.Window.Item;
using LZX.MEditor.WindowLogic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace LZX.MEditor.Window
{
    public class BundleInfoWindow : EditorWindow
    {
        public static Action<ClickEvent> callBack;
        [MenuItem("Tools/LZX/Windows/打包粒度控制窗口")]
        public static void ShowCompositionWindow()
        {
            callBack = null;
            Type rightrootType = typeof(RightRootWindow);
            Type leftrootType = typeof(LeftRootWindow);
            Type inforootType = typeof(InfoWindow);
            //创建最外层Container
            object containerInstance = EditorContainerWindow.CreateInstance();
            //创建分屏容器
            object splitViewInstance = EditorSplitView.CreateInstance();
            //跟容器
            EditorContainerWindow.SetRootView(containerInstance, splitViewInstance);
            #region 左侧合成窗口
            //leftroot与inforoot
            object leftSpliteViewInstance = EditorSplitView.CreateInstance();
            EditorSplitView.SetPosition(leftSpliteViewInstance,new Rect(0,0,600,800));
            //设置垂直状态
            EditorSplitView.SetVertical(leftSpliteViewInstance,true);
            object leftrootDockArea = EditorDockArea.CreateInstance();
            EditorDockArea.SetPosition(leftrootDockArea,new Rect(0,0,600,600));
            EditorWindow leftrootWindow = (EditorWindow) CreateInstance(leftrootType);
            leftrootWindow.titleContent.text = "Bundles";
            EditorDockArea.AddTab(leftrootDockArea,leftrootWindow);
            EditorSplitView.AddChild(leftSpliteViewInstance,leftrootDockArea);
            //inforoot
            object inforootDoceArea = EditorDockArea.CreateInstance();
            EditorDockArea.SetPosition(inforootDoceArea,new Rect(0,0,600,200));
            EditorWindow inforootWindow = (EditorWindow) CreateInstance(inforootType);
            inforootWindow.titleContent.text = "Info";
            EditorDockArea.AddTab(inforootDoceArea,inforootWindow);
            EditorSplitView.AddChild(leftSpliteViewInstance,inforootDoceArea);
            EditorSplitView.AddChild(splitViewInstance,leftSpliteViewInstance);
            #endregion
            #region 右侧合成窗口
            //添加右侧DockArea
            object rightDockAreaInstance = EditorDockArea.CreateInstance();
            EditorDockArea.SetPosition(rightDockAreaInstance, new Rect(0, 0, 200, 800));
            EditorWindow rightrootWindow = (EditorWindow)CreateInstance(rightrootType);
            rightrootWindow.titleContent.text = "Assets";
            EditorDockArea.AddTab(rightDockAreaInstance, rightrootWindow);
            EditorSplitView.AddChild(splitViewInstance, rightDockAreaInstance);
            #endregion
            EditorEditorWindow.MakeParentsSettingsMatchMe(rightrootWindow);
            EditorEditorWindow.MakeParentsSettingsMatchMe(leftrootWindow);
            EditorEditorWindow.MakeParentsSettingsMatchMe(inforootWindow);
            EditorContainerWindow.SetPosition(containerInstance,new Rect(100,100,800,800));
            EditorSplitView.SetPosition(splitViewInstance,new Rect(0,0,800,800));
            EditorContainerWindow.Show(containerInstance,0,true,false,true);
            EditorContainerWindow.OnResize(containerInstance);
            callBack?.Invoke(null);
        }
    }
}
